import App from './App'
import messages from './locale/index'

let i18nConfig = {
	locale: uni.getLocale(),
	messages
}
// #ifndef VUE3
import Vue from 'vue'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
const i18n = new VueI18n(i18nConfig)
// let applicationLocale = uni.getStorageSync('onLanguage') || uni.getLocale();
let applicationLocale = "zh-Hans"
// let applicationLocale = "en"
uni.setStorageSync('onLanguage',applicationLocale)
i18n.locale = applicationLocale;
setTimeout(()=>{
	uni.setLocale(applicationLocale)
	console.log(uni.getLocale());
},0)
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	i18n,
	...App
})
app.$mount()
// #endif

import * as tools from './utils/tools.js'
import {
	myRequest
} from '@/utils/myRequest.js'
Vue.prototype.$myRequest = myRequest
Vue.prototype.$tools = tools
import {websocetObj} from "@/utils/websocket.js"
Vue.prototype.$websocetObj = websocetObj

// #ifdef H5
// 引入uni.webview.1.5.4.js
import './utils/uni.webview.1.5.4.js';
// #endif

// 导入并挂载全局的分享方法
import share from './utils/share.js'
Vue.mixin(share)
Vue.prototype.getImg = function(img) {
	// if((img+'').indexOf('mp4')>-1){
	// 	return 'https://siha.oss-cn-beijing.aliyuncs.com' + img
	// 	// return 'https://siha.vxmeng.com' + img
	// }else{
	// 	return 'https://siha.oss-cn-beijing.aliyuncs.com' + img
	// }
	return (img+"").indexOf('http')>-1?img:('https://siha.oss-cn-beijing.aliyuncs.com' + img)
}
Vue.prototype.comLink = function(e) {
	tools.toLink(e)
}

Vue.prototype.messageFun = function(type,e) {
	uni.webView.postMessage({
		data: {
			action: type,
			data:e
		}
	})
}

// Vue.prototype.chatFun = function(e) {
// 	uni.webView.postMessage({
// 		data: {
// 			action: 'chat',
// 			data:e
// 		}
// 	})
// }

Vue.prototype.$t = (key, value) => i18n.t(key, value)

// 导入并挂载全局的播放音效方法
import music from './utils/music.js'
Vue.prototype.$music = music
import music_mixin from './utils/music_mixin.js'
Vue.mixin(music_mixin)

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
import {
	createI18n
} from 'vue-i18n'
const i18n = createI18n(i18nConfig)
export function createApp() {
	const app = createSSRApp(App)
	app.use(i18n)
	return {
		app
	}
}
// #endif